package com.windaka.elements.model;


import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.Date;
import java.util.List;

/**
 * 用户
 * @author song
 * @date 7:53 下午 2021/11/7
 * @param
 * @return
 * @other
**/
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class SysUser implements UserDetails {

    /**
     * 用户id
     */
    private Integer id;

    /**
     * 角色id
     */
    private Integer roleId;

    /**
     * 账号
     */
    private String username;

    /**
     * 密码(加密的)
     */
    private String password;

    /**
     * 名称
     */
    private String realName;

    /**
     * 是否过期
     */
    private Boolean isExpired;

    /**
     * 是否锁定
     */
    private Boolean isLock;

    /**
     * 是否认证
     */
    private Boolean isCredentials;

    /**
     * 是否可用
     */
    private Boolean isEnable;

    /**
     * 创建时间
     */
    private Date createTime;

    /**
     * 登录时间
     */
    private Date loginTime;

    /**
     * dept_id 归属部门多个以逗号隔开
     **/
    private Integer deptId;

    /**
     * img_url 头像
     **/
    private String imgUrl;

    /**
     * user_status 账号状态 1:正常 2:禁用
     **/
    private Integer userStatus;


    /**
     * 角色列表
     */
    private List<GrantedAuthority> authorities;

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return authorities;
    }

    @Override
    public String getPassword() {
        return password;
    }

    @Override
    public String getUsername() {
        return username;
    }

    @Override
    public boolean isAccountNonExpired() {
        return isExpired;
    }

    @Override
    public boolean isAccountNonLocked() {
        return isLock;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return isCredentials;
    }

    @Override
    public boolean isEnabled() {
        return isEnable;
    }

}
